<template>
  <div class="c-button dir-next" v-if="dir==='next'" :style="styleObject" @click="dirClick(dir)">
    <slot name="nextButton"></slot>
    <div v-if="!$slots.nextButton">
      <i class="iconfont icon-jiantouyou"></i>
    </div>
  </div>
  <div
    class="c-button dir-prev"
    v-else-if="dir==='prev'"
    :style="styleObject"
    @click="dirClick(dir)"
  >
    <slot name="prevButton"></slot>
    <div v-if="!$slots.prevButton">
      <i class="iconfont icon-jiantouzuo"></i>
    </div>
  </div>
</template>

<script>
import { computed,getCurrentInstance } from 'vue';
export default {
    name:"CButton",
    props: {
        dir:String,
        hasDirector:Boolean,
        dotBgColor:{
            type:String,
            default:"red"
        },
    },
    computed:{
        styleObject(){ // vue背景颜色变量绑定
            return{
                "--background-color-hover":this.dotBgColor
            }
        }
    },
    setup(props,ctx) {
        const dirClick = (dir)=>{
            ctx.emit("dirClick",dir);
        }
        return{
            dirClick
        }
    }
}
</script>

<style lang="scss" scoped>
.dir-next {
  right: 0;
  justify-content: flex-end;
}
.dir-prev {
  left: 0;
}
.c-button {
  position: absolute;
  z-index: 3;
  width: 10%;
  height: 100%;
  display: flex;
  align-items: center;
  transition-duration: 0.5s;
  div {
    width: 26px;
    height: 26px;
    text-align: center;
    line-height: 26px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    position: absolute;
    top: 50%;
    z-index: 4;
    margin-top: -20px;
    cursor: pointer;
  }
}
</style>